<?php

class RequirementFaultsController extends AppController {

    var $name = 'RequirementFaults';

    public function index($requirement_id = null) {
        $requerimientos = $this->RequirementFault->find('all', array(
            'recursive' => -1,
            'conditions' => array('RequirementFault.requirement_id' => $requirement_id),
            'fields' => array('RequirementFault.nombre', 'RequirementFault.tipo', 'RequirementFault.id')
                ));
        $call_id = $this->RequirementFault->Requirement->field('call_id');
        $this->set('req', $requerimientos);
        $this->set('requirement_id', $requirement_id);
        $this->set('call_id', $call_id);
    }

    public function add($id = null) {
        $this->layout = "ajax";
        if (empty($this->data)) {
            $this->data['RequirementFault']['requirement_id'] = $id;
        } else {
            if ($this->RequirementFault->saveAll($this->data)) {
                $ide = $this->data['RequirementFault']['requirement_id'];
                $this->setAction("index", $ide);
                $this->Session->setFlash('Restricción adicionada');
            } else {
                
            }
        }
    }

    public function delete($id, $req) {
        if ($this->RequirementFault->del($id)) {
            $this->setAction("index", $req);
            $this->Session->setFlash('Restricción eliminada  con éxito');
        }
    }

    public function edit($id = null) {
        $this->layout = "ajax";
        if (empty($this->data)) {
            $this->data = $this->RequirementFault->find("first", array('recursive' => -1, "conditions" => array("RequirementFault.id" => $id)));
        } else {
            if ($this->RequirementFault->saveAll($this->data)) {
                $this->Session->setFlash('Restricción editada con éxito');
                $ide = $this->data['RequirementFault']['requirement_id'];
                $this->setAction("index", $ide);
            }
        }
    }

}

?>
